local UIBase = require("view.UIBase")
local MailView = class("MailView", UIBase)
local UIUtil = require("utils.UIUtil")
local GameUtils = require("utils.GameUtils")

function MailView:ctor()
    local resource = {
        path = "Prefabs/View",
        name = "MailView",
        canvas = 2
    }
    MailView.super.ctor(self, resource)
end

function MailView:start()
    self._listView = self._listMails:GetComponent(typeof(CS.CommonScrollView))
    UIUtil.addTouchEvent(self._panelTouch.transform, nil, nil, handler(self, self._onPanelTouch))

    self._signalMailNotify = G_SignalManager:add(SignalConst.EVENT_MAIL_NOTIFY, handler(self, self._onEventMailNotify))
    self._signalMailGetAll = G_SignalManager:add(SignalConst.EVENT_MAIL_GET_ALL, handler(self, self._onEventGetMail))

    self._listView:SetTemplate(
        handler(self, self._onItemUpdate),
        handler(self, self._onValueChange),
        handler(self, self._onItemTouch)
    )
end

function MailView:onDestroy()
    self._signalMailNotify:remove()
    self._signalMailNotify = nil
    self._signalMailGetAll:remove()
    self._signalMailGetAll = nil
end

function MailView:_updateView()
    self._datas = G_UserData:getMail():getMailList()
    self._listView:ReSize(#self._datas)
end

function MailView:_onItemUpdate(item, index)
    local startIndex = index + 1
    local data = self._datas[startIndex]
    item:updateUI(data)
end

function MailView:_onValueChange()
end

function MailView:_onItemTouch(item, index)
end

function MailView:_onEventMailNotify(id, message)
end

function MailView:_onEventGetMail(id, message)
end

function MailView:_onPanelTouch()
    self:close()
end

return MailView
